import {useState,useReducer } from "react"
import { produce } from 'immer'

function reducer(state,action){
    switch(action.type){
        case 'add':
            // return {
            //     result: state.result + action.num
            // } 
            return produce(state,(state) =>{
                
            })
        case 'minus':
            return {
                result : state.result - action.num
            }
    }
}

function App() {
    // useReducer 接受的第二个的参数
  const [res,dispatch] =useReducer(reducer,{result: 0})
  return (
    <div>
      <h3>{res.result}</h3>
      <button onClick={()=>dispatch({type:'add',num:2})}>+</button>
      <button onClick={()=>dispatch({type:'minus',num:1})}>-</button>
    </div>
  )
}

export default App